package bsts.application;

import bsts.controller.BillController;
import bsts.controller.CustomerController;
import bsts.controller.SubscriptionController;
import bsts.controller.UserController;
import bsts.controller.ViewController;
import bsts.model.User;
import bsts.model.UserRole;

public class BSTSApplication {

	private ViewController viewManager;
	private UserController userManager;
	private CustomerController customerManager;
	private SubscriptionController subscriptionManager;
	private BillController billManager;
	private User loginUser;

	public static void main(String[] args) {
		BSTSApplication bstsApplication = new BSTSApplication();
		bstsApplication.start();
	}

	public BSTSApplication() {
		viewManager = new ViewController(this);
	}

	public void start() {
		viewManager.showLoginWindow();
	}

	public void loginSuccess(User loginUser) {
		this.loginUser = loginUser;
		viewManager.hideLoginWindow();
		viewManager.showMainwindow(this);
	}

	public void logout() {
		this.loginUser = null;
		viewManager.showLoginWindow();
		viewManager.disposeUserWindows();
	}

	public void shutdown() {
		System.exit(1);
	}

	public User getLoginUser() {
		return loginUser;
	}

	public boolean isAdminRole() {
		if (getLoginUser().getUserRole().equals(UserRole.Admin))
			return true;

		return false;
	}

	// return manager instance
	public ViewController getViewManager() {
		return viewManager;
	}

	public UserController getUserManager() {
		if (userManager == null)
			userManager = new UserController();

		return userManager;
	}

	public CustomerController getCustomerManager() {
		if (customerManager == null)
			customerManager = new CustomerController();

		return customerManager;
	}
	
	public SubscriptionController getSubscriptionManager() {
		if (subscriptionManager == null)
			subscriptionManager = new SubscriptionController();
		
		return subscriptionManager;
	}

	public BillController getBillManager() {
		if (billManager == null)
			billManager = new BillController();

		return billManager;
	}

}
